#include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <numeric>
#include <ctime>
#include <cmath>
using namespace std;

class Student{
public:
    Student(string name, int chinese, int math, int english);
    ~Student();

    friend ostream& operator<<(ostream& os, const Student& rhs);
//    int get_sum() {return _sum;}
//private:
    string _name;
    int _chinese;
    int _math;
    int _english;
    int _sum;
};

Student::Student(string name, int chinese, int math, int english)
    :_name(name)
    ,_chinese(chinese)
    ,_math(math)
    ,_english(english)
    ,_sum(chinese + math + english){
}

ostream& operator<<(ostream& os, const Student& rhs){
//    cout << "name: " << rhs._name << "\n";
//    cout << "score: " << rhs._score << endl;
    os << "name: " << rhs._name << "\n"
       << "score: " 
       << rhs._chinese << " "
       << rhs._math << " " 
       << rhs._english << " "
       << rhs._sum << "\n";

    return os;
}

Student::~Student(){}

bool stu_compare(Student& stu1, Student& stu2){
    if(stu1._sum != stu2._sum){
        return stu1._sum > stu2._sum;
    }else{
        return stu1._chinese > stu2._chinese;
    }
}

void test(){
    std::srand(std::time(nullptr));
    Student A("Amy", 85, 90, 78);
    Student B("Bob", 90, 88, 92);
    Student C("Cindy", 90, 85, 80);
    list<Student> stus = {A, B, C};  // 初始化5名选手

    stus.sort(stu_compare);

    // 输出结果
    for (auto& stu : stus) {
        std::cout << stu << std::endl;
    }
}

int main()
{
    test();
    return 0;
}

